﻿define(function (require, exports, module) {
    var Canvas = require('util/canvas');
    var Request = require('util/request');
    var IMain = require('iMain');

    exports.loadAsync = eval(Wind.compile('async', function (leftRole) {
        $await(IMain.renderAsync());

        if (null != leftRole) {
            var response = $await(Request.ajaxAsync({ url: 'chooseRole.do', data: { isLeft: leftRole} }));
            if (!response.success) {
                $await(require('error').loadAsync());
                return;
            }
        }

        var response = $await(Request.ajaxAsync({ url: 'load.do' }));
        $await(require('map').loadAsync(response.map));
    }));
});